<template>
	<view>
		<web-view :src="allUrl"></web-view>
	</view>
</template>

<script>
	import { API_URL } from "@/env.js"
	import { detailedDownload } from "@/common/api.js"
	
	export default {
		data() {
			return {
				pdfUrl: "/hybrid/html/web/viewer.html?file=",
				allUrl: "",
				id: null
			}
		},
		methods: {
			async initPDF() {
				uni.downloadFile({
					url: API_URL + `/api/Invoice/${this.id}`,
					header: {
						Authorization: uni.getStorageSync('token'),
					},
					success: (res) => {
						if (res.statusCode === 200) {
							console.log(res);
							
							this.allUrl = this.pdfUrl + encodeURIComponent(res.tempFilePath);
							console.log(this.allUrl);
						}
						
					}
				});
				// const res = await detailedDownload(this.id);
				// let pdfData = res; //pdfData是后端返回的文件流
				// let blob = new Blob([pdfData], {
				// 	type: 'application/pdf'
				// })
				// pdfData = window.URL.createObjectURL(blob) //创建预览路径
				// console.log(pdfData);
				// this.allUrl = this.pdfUrl+encodeURIComponent(pdfData)
				// console.log(this.allUrl);
			}
		},
		onLoad(option) {
			this.id = option.id;
			this.initPDF();
		}
	}
</script>

<style lang="scss" scoped>

</style>